package com.licheedev.somektxdemo

import android.view.LayoutInflater
import android.view.ViewGroup
import com.licheedev.myutils.LogPlus
import com.licheedev.someext.recycler.*
import com.licheedev.somektxdemo.databinding.ItemSampleDataBinding

class SampleAdatper : SimpleBindingRecyclerAdapter<SampleData, ItemSampleDataBinding>() {

    override fun bindingInflate(): (LayoutInflater, ViewGroup, Boolean) -> ItemSampleDataBinding {
        return ItemSampleDataBinding::inflate
    }

    override fun onBindViewHolder(holder: BindingViewHolder<ItemSampleDataBinding>, position: Int) {

        val item = getItem(position)
        val binding = holder.binding
        binding.item = item
        binding.btnClick.bindOnclickListener(holder) { currentPos ->
            LogPlus.e("点击了,curentPos=$currentPos,bindingPos=$position,data=${getItem(currentPos)}")
            getItem(currentPos).text = "我改了"
            notifyItemChanged(currentPos, "null")
        }
        
        binding.btnDelete.bindOnclickListener(holder) { currentPos ->
            LogPlus.e("要删除,curentPos=$currentPos,bindingPos=$position,data=${getItem(currentPos)}")
            delete(currentPos)
        }
    }

} 